<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <fredbird@fredbird.org>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* webappkit triggers main management
* retrieves triggers from triggersStore and derivated instances
* @uses triggerStore
* @author J.Ducastel <fredbird@fredbird.org>
* @version 
*/
class wakTriggers extends wakService {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	* /
	function wakTriggers() {
		$this->__construct();
	}/**/
	
	/**
	*
	* @access
	* /
	function __construct() {
		parent::__construct();
		// build stores

	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param int $step
	* @param wakhttprequest $request
	* @param bool $fromCore
	* @access public
	* @return array of wakTrigger
	*/
	function getRequestTriggers($request,$step=1,$fromCore=false) {
		// getting appropriate store
		if (!$store=&$this->getstore($step,$fromCore))
			return array();
		// gather and return triggers
		return $store->getrequesttriggers($request);
	}/**/
	
	/**
	* builds triggers pile for http request
	* @param wakhttprequest $request
	* @param bool $fromCore if true, gets triggers form core sources
	* @access public
	* @return bool
	*/
	function buildRequestTriggersPile($request,$fromCore=false) {
		$pile=&wak::getservice('waktriggerspile');
		for ($step=1; $step<=7; $step++) {

			if ($store=&$this->getstore($step,$fromCore))
				$store->requestTriggersToPile($request);
		}
		$deb=&wak::getservice('wakdebug');
		//echo $pile->dumpAsText();
		//echo $deb->vardump($pile);
		return true;
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var array service config
	*/
	var $cfg=array();
	/**
	* @var type desc
	*/
	//var //
	var $stores=array(); // databeanStore instances step => instance
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* return wakdatabeanstore appropriate instance
	* @param int $step 1-7
	* @param bool $core core or app triggers ?
	* @access private
	* @return wakDatabeanStore
	*/
	function & getStore($step=1,$core=false) {
		if (!isset($this->stores[$step]) or !$this->stores[$step]) {
			// store not built
			if ($core or $step==1) {
				// getting core triggers
				$lib=&wak::getservice('waklib');
				$lib->needclass('waktriggerstore_ini');
				$file=WAK_CORE_PATH."cfg/triggers-$step.store.ini";
				$this->stores[$step]=&new waktriggerstore_ini($file);
			} else {
				// getting app triggers
				// $this->stores[$step]=false;
				$lib=&wak::getservice('waklib');
				$lib->needclass('waktriggerstore_ini');
				$file="cfg/triggers-$step.store.ini";
				$this->stores[$step]=&new waktriggerstore_ini($file);
			}
		}
		return $this->stores[$step];
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
